package com.itqn.servlet;

import com.alibaba.fastjson.JSONArray;
import com.itqn.service.Impl.ProductServiceImpl;
import com.itqn.service.ProductService;
import lombok.SneakyThrows;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(value = "/ProductDeleteServlet")
public class ProductDeleteServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @SneakyThrows
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取请求参数
        String id = request.getParameter("id");
        //创建业务逻辑层对象
        ProductService productService=new ProductServiceImpl();
        //调用删除的方法
        int result = productService.deleteGoods(Integer.parseInt(id));
        PrintWriter writer = response.getWriter();
        writer.write(result>0?"ok":"no");
    }
}
